import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import svgInject from "./plugins/svg.inject";

export default defineConfig({
  plugins: [vue(), svgInject()],

  server: {
    // port: 8080,
    // open: true, // 自动打开浏览器
    cors: true, // 允许跨域
  },

  resolve: {
    alias: {
      "@": resolve(__dirname, "src"), // 设置 @ 指向 src 目录
    },
  },

  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/assets/css/base.scss";`, // 全局引入 base.scss
      },
    },
  },

  build: {
    terserOptions: {
      compress: {
        drop_console: true, // 生产环境移除 console
        drop_debugger: true, // 生产环境移除 debugger
      },
    },
    rollupOptions: {
      output: {
        chunkFileSize: 1500, // 分块打包，单个文件大小限制（KB）
        manualChunks(id) {
          // 手动分包
          if (id.includes("node_modules")) {
            return "vendor";
          }
        },
      },
    },
  },
});
